﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace pcsse.management
{
    public partial class branch : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Priority"] != null)
            {
                int pri = Convert.ToInt32(Session["Priority"].ToString());
                if (pri <= 3)
                {
                    Response.Redirect("~/default.aspx");
                }
            }
            errLb.Text = "";
            bDv.Visible = false;
        }

        protected void errHandle(Exception e)
        {
            if (e is System.Data.SqlClient.SqlException)
            {
                errLb.Text = "[年份+支部]是唯一的";
            }
            else if (e is NoNullAllowedException)
            {
                errLb.Text = "请将信息填写完整";
            }
            else if (e is ArgumentException)
            {
                errLb.Text = "非法参数";
            }
            else
            {
                errLb.Text = "未知错误";
                errLb.Text += e.Message.ToString();
            }
        }
        protected void branchGv_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {
            if (e.Exception != null)
            {
                Exception inner = e.Exception.InnerException;
                errHandle(inner);
                e.ExceptionHandled = true;
                e.KeepInEditMode = true;
            }
        }

        protected void bDv_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
        {
            if (e.Exception != null)
            {
                Exception inner = e.Exception.InnerException;
                errHandle(inner);
                e.ExceptionHandled = true;
                e.KeepInInsertMode = true;
                bDv.Visible = true;
            }else{
                bDv.Visible = false;
            }
        }

        protected void AddBt_Click(object sender, EventArgs e)
        {
            bDv.Visible = true;
        }
    }
}
